package com.pengshun.modules.api.user.controller;

import com.pengshun.modules.api.coal.service.dto.MerchantDto;
import com.pengshun.modules.api.coal.validator.Fifth;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Seventh;
import com.pengshun.modules.api.user.para.UserPara;
import com.pengshun.modules.api.user.service.AuthenticationService;
import com.pengshun.modules.api.user.service.dto.CarOwnerDto;
import com.pengshun.modules.api.user.service.dto.CitizenDto;
import com.pengshun.modules.api.user.service.dto.DrivingLicenseDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "认证管理")
@RequestMapping("/api/user/authentication")
@ApiIgnore
public class AuthenticationController     {

    private final AuthenticationService authenticationService;

    @ApiOperation(value = "实名认证保存/修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardNum", value = "身份证号", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardFrontImg", value = "正面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardBackImg", value = "反面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "认证id(存在代表修改)", dataType = "int", paramType = "query"),
    })
    @PostMapping(value = "/idcard", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult idcard(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fifth.class}) CitizenDto para) throws Exception {
            para.setUserId(user.getId());
        BaseResult res = authenticationService.idcard(para);
        return res;
    }

    @ApiOperation(value = "司机认证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idcard", value = "身份证号", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardFrontImg", value = "正面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardBackImg", value = "反面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "dlImageFront", value = "驾驶证照片正面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "dlImageBack", value = "驾驶证照片反面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "drivingLicenseId", value = "认证id(存在代表修改)", dataType = "int", paramType = "query"),
    })
    @PostMapping(value = "/driver", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult driver(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) DrivingLicenseDto para,  @ApiIgnore CitizenDto dto) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = authenticationService.driver(para, dto);
        return res;
    }

    @ApiOperation(value = "车主认证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "姓名", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardNum", value = "身份证号", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardFrontImg", value = "正面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardBackImg", value = "反面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "认证id(存在代表修改)", dataType = "int", paramType = "query"),
    })
    @PostMapping(value = "/carowner", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult carowner(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) CitizenDto para ) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = authenticationService.carowner(para);
        return res;
    }

    @ApiOperation(value = "商户认证")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商户id(有则代表修改)", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "merchantCategoryId", value = "商户类别id 1经销商 2 运输公司", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "wayPic", value = "道路许可证", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "isLegalPerson", value = "是否法人 0 否  1是", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "idCardNum", value = "身份证号", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardFrontImg", value = "正面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardBackImg", value = "反面", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "idCardFrontImgs", value = "法人正面", dataType = "string",   paramType = "query"),
            @ApiImplicitParam(name = "idCardBackImgs", value = "法人反面", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "double",  paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "double",  paramType = "query"),
            @ApiImplicitParam(name = "province", value = "省份", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "city", value = "城市", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "district", value = "区县", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "adcode", value = "区县id", dataType = "int",  paramType = "query"),
            @ApiImplicitParam(name = "detailAddress", value = "详细地址", dataType = "int",  paramType = "query"),

            @ApiImplicitParam(name = "name", value = "商户名称", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "businessLicenseImg", value = "营业执照", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "doorImg", value = "门头照片", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "linkman", value = "联系人", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "linkmanPhone", value = "联系人电话", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "bookPic", value = "授权书", dataType = "string",  paramType = "query"),
    })
    @PostMapping(value = "/merchant", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult merchant(@ApiIgnore @CurrUserInfo User user, @ApiIgnore   MerchantDto para ,@ApiIgnore @Validated(value = {First.class}) CitizenDto paras) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = authenticationService.merchant(para,paras);
        return res;
    }

    @ApiOperation(value = "认证信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userType", value = "0:普通用户,1司机,2车主,3运输公司,4煤炭商,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/authentication", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult autentication(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Seventh.class}) UserPara para) throws Exception {
        para.setId(user.getId());
        BaseResult res = authenticationService.getAutentication(para);
        return res;
    }

}
